/**
 * Created by dio on 2017/2/28 0028.
 */
import React from "react";
import {ActivityIndicator, InteractionManager, ScrollView, View} from "react-native";
import chjStyle from "../../CustomStyle";
import CommonTextItem from "../record/common/CommonTextItem";
import ModuleCommonHeader from "../module/ModuleCommonHeader";

export default class MoreCarParams extends React.Component
{
    // 构造函数，可执行初始化操作
    constructor(props)
    {
        super(props);
        this.state = {
            isLoading: true
        };
    }

    // 组件被加载时
    componentDidMount()
    {
        InteractionManager.runAfterInteractions(()=>{
            this.setState(
                {
                    isLoading:false
                }
            )
        });
    }

    // 组件即将被卸载时
    componentWillUnmount()
    {
    }

    // 组件被渲染时
    render()
    {
        if (this.state.isLoading)
        {
            if (this.state.isLoading) {
                return (
                    <View>
                        <ModuleCommonHeader title={this.props.title} leftText='返回'/>
                    <ActivityIndicator
                        animating={true}
                        style={{alignItems: 'center', justifyContent: 'center', height: chjStyle.height}}
                        size="large" />
                    </View>);
            }
        }
        return(
            <View>
                <ModuleCommonHeader title='车辆参数详细' leftText='返回'/>
                <ScrollView
                    showsVerticalScrollIndicator={false}
                    style={[chjStyle.recordContainer,{backgroundColor: '#fff'}]}>
                    {
                        this.props.params.map(
                            (item,i)=>this.renderItem(item,i)
                        )
                    }
                </ScrollView>
            </View>
        );
    }

    renderItem(item, i)
    {
        if (item.keyname.indexOf('推定里程') === -1)
        return (<CommonTextItem object={{name:item.keyname, value:item.keyvalue}}/>);
    }
}

